package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Tel      string `json:"tel" gorm:"type:char(11);not null;unique;comment:'手机号'"`
	Password string `json:"password" gorm:"type:char(32);comment:'密码'"`
	NickName string `json:"nickName" gorm:"type:varchar(32);comment:'昵称'"`
}

func (u *User) Register() error {
	return DB.Create(&u).Error
}

func (u *User) Login(tel string) (user User, err error) {
	err = DB.Where("tel=?", tel).Limit(1).Find(&user).Error
	return
}
